package com.admin.business.portalWebsite.venusSysSearchRecords;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 门户网搜索记录
 * @create: 2023-11-21 14:18:29
 **/
@Service("venusSysSearchRecordsService")
@Slf4j
public class VenusSysSearchRecordsService{

    @Resource
    VenusSysSearchRecordsDao venusSysSearchRecordsDao;

    /**
     * 添加门户网搜索记录,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - content:搜索内容
     *                   - type:类型 1:商业合作
     *                   - begin_time:创建时间
     *                   - state:状态 0:正常 1删除
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return addVenusSysSearchRecords(CDO cdoRequest) {
        venusSysSearchRecordsDao.addVenusSysSearchRecords(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新门户网搜索记录数据
     *
     * @param cdoRequest - id:主键id
     *                   - content:搜索内容
     *                   - type:类型 1:商业合作
     *                   - begin_time:创建时间
     *                   - state:状态 0:正常 1删除
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return updateVenusSysSearchRecordsById(CDO cdoRequest) {
        venusSysSearchRecordsDao.updateVenusSysSearchRecordsById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除门户网搜索记录数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusSysSearchRecordsById(CDO cdoRequest){
        int count = venusSysSearchRecordsDao.deleteVenusSysSearchRecordsById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除门户网搜索记录数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusSysSearchRecords(CDO cdoRequest) {
        int count = venusSysSearchRecordsDao.deleteVenusSysSearchRecords(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取门户网搜索记录数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusSysSearchRecordsById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysSearchRecordsDao.getVenusSysSearchRecordsById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取门户网搜索记录数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusSysSearchRecordsListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysSearchRecordsDao.getVenusSysSearchRecordsListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysSearchRecordsDao.getVenusSysSearchRecordsCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取门户网搜索记录数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusSysSearchRecordsListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysSearchRecordsDao.getVenusSysSearchRecordsListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysSearchRecordsDao.getVenusSysSearchRecordsCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
